﻿package net.wangit.dev.incrementor;

import net.wangit.context.ActionContext;
import net.wangit.dev.DomainAction;
import net.wangit.dev.ObjectChecker;
import net.wangit.jdbc.DB;
import net.wangit.jdbc.generator.IncrementorCache;
import net.wangit.util.Checker;

public class DeleteIncrementorAction extends DomainAction {

	private static final String SQL_CHECK = "select l from INCREMENTOR where iid=?";
	private static final String SQL_DELETE = "delete from INCREMENTOR where iid=?";

	public DeleteIncrementorAction() {
	}

	public void doAction(DB db, ActionContext ac) throws Exception {
		String iid = ac.getRequestParameter("iid");
		if (!Checker.isEmpty(iid)) {
			net.wangit.MapList list = db.query(
					DeleteIncrementorAction.SQL_CHECK, iid, 2);
			if (ObjectChecker.invalid(ac, list, "l"))
				return;
			db.execute(DeleteIncrementorAction.SQL_DELETE, iid, 2);
			IncrementorCache.clear(domain, iid);
			IncrementorReferenceUtil.update(db, domain, iid, "");
		}
	}
}
